ind1_train = df3$f471>3.5
ind2_train = df3$f468>1.8
ind3_train = df3$f471>7

pred_train = ind1_train*3 + ind2_train*3 + ind3_train*1 + ind1_train*ind2_train*(-2)

df_resid = df3
df_resid$loss = df_resid$loss - pred_train

sort(sapply(df_resid[,2:780],function(x) mean(df_resid$loss[x >= quantile(x, .9995)]>0)), decr=T)[1:10]

sort(sapply(df_resid[,2:780],function(x) mean(df_resid$loss[x <= quantile(x, .001)]>0)), decr=T)[1:10]


sum(df3$f471>3.3) #61
sum(df3$f471>3.9) #51
sum(df3$f471>4.6) #41
sum(df3$f471>6)   #31
sum(df3$f471>7.1) #21
sum(df3$f471>8.5) #11

min(df3$f471) #1.0

v = cut(df3$f471, c(1,3.3, 3.9, 4.6, 6, 7.1, 8.5), include.lowest=T)
u = tapply(df3$loss, v, mean)
u1 = df3$f471 > 3.9

rq(df3$loss~v)





